package com.hlc.jxls.controller;

import com.hlc.jxls.Student;
import com.hlc.jxls.common.ExcelUitl;
import net.sf.jxls.transformer.XLSTransformer;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017-03-26.
 */
@RestController
@RequestMapping("/testExcel")

public class TestExcel{

    @ResponseBody
    @RequestMapping("/excel")
    public void excel(){
        List<Student> sts=new ArrayList<Student>();
        Student stu1=new Student();
        stu1.setId(1);
        stu1.setAge(12);
        stu1.setName("helinchong");
        stu1.setSex("男");
        Map map=new HashMap();
        map.put("stu",sts);
        XLSTransformer former = new XLSTransformer();
        //获取java项目编译后根路径
        URL url = this.getClass().getClassLoader().getResource("");
        try {
            former.transformXLS(url.getPath()+"student.xls",map , "D:/student.xls");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
